<?php
App::uses('AppHelper', 'View/Helper');
class CartHelper extends AppHelper {
	
	public function Widget(){
		$panel = '';
		if(!$this->Session->check('cart') || sizeof($this->Session->read('cart'))==0){
			$panel = $this->WidgetCartEmpty();
		}else{
			$panel = $this->WidgetCartNotEmpty();
		}
		return $panel;
	}
	
	private function WidgetCartEmpty(){
		$panel = $this->Html->link(
							'<i class=\'icon-shopping-cart\'></i>Pannier: <span id=\'shoppingCartValue\'></span>',
							'#',
							array(
								'escape'=>false,
								'class'=> 'disabled dropdown-toggle',
								'data-toggle'=>'dropdown'								
							)
						).
				'<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">'.
				'<li>'.
					$this->Html->link('Validez le pannier',
								array(
									'controller'=>'orders',
									'action'=>'index'
								)
							).
				'</li>'.
				'<li>'.
				$this->Html->link('Videz le pannier',
								array(
									'controller'=>'orders',
									'action'=>'emptyCart'
								),
								array('escape'=>false)
							).
				'</li>'.
			'</ul>';
		
		return $panel;
	}
	
	private function WidgetCartNotEmpty(){
		$panel = '';
		
		$totalPrice = $this->Session->read('cart.summary.totalPrice');
		
		$panel .=$this->Html->link(
							'<i class=\'icon-shopping-cart\'></i>Pannier: &euro;'.$totalPrice.' <i class="caret"></i>',
							'#',
							array(
								'escape'=>false,
								'data-toggle'=>'dropdown',
								'class'=>'dropdown-toggle'
							)
						).
			'<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">'.
			'<li>'.
			$this->Html->link('Validez le pannier',
								array(
									'controller'=>'orders',
									'action'=>'index'
								)
							).
				'</li>'.
				'<li>'.
				$this->Html->link('Videz le pannier',
								array(
									'controller'=>'orders',
									'action'=>'emptyCart'
								),
								array('escape'=>false)
							).
				'</li>'.
			'</ul>';
		return $panel;
	}									
}
?>